package cn.itsource.controller.remote;

import cn.itsource.api.DriverPointApi;
import cn.itsource.pojo.domain.DriverPoint;
import cn.itsource.pojo.result.DriverPointResult;
import cn.itsource.result.JSONResult;
import cn.itsource.service.IDriverPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DrvierPointApiImpl implements DriverPointApi {

    @Autowired
    private IDriverPointService driverPointService;

    @Override
    public JSONResult<List<DriverPointResult>> selectByOrderNo(String orderNo) {

        List<DriverPoint> driverPoints = driverPointService.selectByOrderNo(orderNo);
        //使用stream把List<DriverPoint>转换为List<DriverPointResult>
        List<DriverPointResult> resultList = driverPoints.stream().map(point -> new DriverPointResult(point.getLongitude(), point.getLatitude()) )
                .collect(java.util.stream.Collectors.toList());

        return JSONResult.success(resultList);
    }
}
